//
//  KADetailCell.m
//  KeepAccount
//
//  Created by Veer on 2017/12/19.
//  Copyright © 2017年 Veer. All rights reserved.
//

#import "KADetailCell.h"

#import "KAAccountModel.h"
#import "KACategoryModel.h"
#import "NSString+Tools.h"

@interface KADetailCell()

/** icon */
@property (nonatomic, weak) UIImageView *iconImgView;
/** title */
@property (nonatomic, weak) UILabel *titleLbl;
/** money */
@property (nonatomic, weak) UILabel *moneyLbl;
/** money */
@property (nonatomic, weak) UIView *bottomLineView;

@end

@implementation KADetailCell

+ (instancetype)cellWith:(UITableView *)tablevie
{
    static NSString *cellID = @"KADetailCell";
    
    KADetailCell *cell = [tablevie dequeueReusableCellWithIdentifier:cellID];
    if (nil == cell) {
        
        cell = [[KADetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.accessoryType = UITableViewCellAccessoryNone;
//        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self setupSubView];
        
    }
    return self;
}


- (void)setupSubView
{
    
    UIView *selectedBgView = [[UIView alloc] init];
    selectedBgView.backgroundColor = RGB(238, 238, 238);
    self.selectedBackgroundView = selectedBgView;
    
    UIImageView *dropImgView = [[UIImageView alloc] init];
    dropImgView.image = [UIImage imageNamed:@"category_e_shopping_s"];
    [self.contentView addSubview:dropImgView];
    self.iconImgView = dropImgView;
    [dropImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView);
        make.left.mas_equalTo(15);
        make.width.mas_equalTo(36);
        make.height.mas_equalTo(36);
    }];
    
    // 标题
    UILabel *titleLbl = [[UILabel alloc] init];
    titleLbl.text = @"社交";
    titleLbl.font = [UIFont systemFontOfSize:16];
    titleLbl.textColor = RGB(51, 51, 51);
    [self.contentView addSubview:titleLbl];
    self.titleLbl = titleLbl;
    [titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView);
        make.left.mas_equalTo(dropImgView.mas_right).offset(15);
    }];
    
    // 金额
    UILabel *moneyLbl = [[UILabel alloc] init];
    moneyLbl.text = @"-50";
    moneyLbl.font = [UIFont systemFontOfSize:16];
    moneyLbl.textColor = RGB(51, 51, 51);
    moneyLbl.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:moneyLbl];
    self.moneyLbl = moneyLbl;
    [moneyLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView);
        make.right.mas_equalTo(-15);
    }];
    
    // 线
    UIView *hLineView = [[UIView alloc] init];
    hLineView.backgroundColor = RGB(225, 225, 225);
    [self.contentView addSubview:hLineView];
    self.bottomLineView = hLineView;
    [hLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.contentView);
        make.left.right.mas_equalTo(self.contentView);
        make.height.mas_equalTo(0.5);
    }];
}


#pragma mark setter && getter
- (void)setLineType:(LineType)lineType
{
    _lineType = lineType;
    if (lineType == LineTypeCenter) {

        self.bottomLineView.hidden = NO;
        self.bottomLineView.transform = CGAffineTransformMakeTranslation(65, 0);
    }else if (lineType == LineTypeCenterAndBottom){

        self.bottomLineView.hidden = YES;
    }else{

        self.bottomLineView.hidden = NO;
        self.bottomLineView.transform = CGAffineTransformMakeTranslation(0, 0);
    }
}

- (void)setAccountModel:(KAAccountModel *)accountModel
{
    _accountModel = accountModel;
    
    self.iconImgView.image = [UIImage imageNamed:accountModel.categoryModel.image_s];
    if (accountModel.note.length > 0) {
        self.titleLbl.text = accountModel.note;
    }else{
        self.titleLbl.text = accountModel.categoryModel.name;
    }
    self.moneyLbl.text = [NSString moneyWith:accountModel.type == 1 ? accountModel.money : -1 * accountModel.money];
}

@end
